var JustShare;

if (JustShare == undefined)
	JustShare = new function() {

		// Self reference.
		var JustShare = this;

		this.title = "";
		this.utl = "";

		this.share = function send(event) {

			var action = event.currentTarget.dataset.action;

			action = action.replace("<TITLE>", JustShare.title);
			action = action.replace("<URL>", JustShare.url);
			action = action.replace("<CONTENT>", JustShare.title + " (" + JustShare.url
					+ ") Via @JustShare");

			chrome.tabs.create({
				url : action,
			}, function callback() {
				window.close();
			});

		};

		this.load = function load(event) {
			chrome.tabs.query({
				currentWindow : true,
				active : true
			}, function callback(tabs) {
				var tab = tabs[0];
				JustShare.title = tab.title;
				JustShare.url = tab.url;

				var shares = document.getElementsByTagName("td");
				for ( var i = 0; i < shares.length; i++) {
					shares[i].addEventListener("click", JustShare.share);
				}
			});

		};
	};

window.addEventListener("load", JustShare.load);
